signed int get_tz_offset();
time_t mklocaltime(struct tm* t);
time_t mkgmtime(struct tm* t);
+bool gpsbabel_testmode();
gpsbabel::DateTime current_time();
void dotnet_time_to_time_t(double dotnet, time_t* t, int* millisecs);
signed int month_lookup(const char* m);
static void
garmin_gpi_wr_init(const QString& fname)
{
- if (gpi_timestamp != 0) { /* not the first gpi output session */
+ if ((gpi_timestamp != 0) && !gpsbabel_testmode()) { /* not the first gpi output session */
time_t t = time(nullptr);
if (t <= gpi_timestamp) {
gpi_timestamp++; /* don't create files with same timestamp */
gpi_timestamp = t;
}
} else {
- gpi_timestamp = gpsbabel_time; /* always ZERO during 'testo' */
+ gpi_timestamp = gpsbabel_time;
}
fout = gbfopen_le(fname, "wb", MYNAME);
mkshort_del_handle(&short_h);
gbfclose(fout);
- if ((opt_sleep) && (gpi_timestamp != 0)) { /* don't sleep during 'testo' */
+ if ((opt_sleep) && !gpsbabel_testmode()) { /* don't sleep during 'testo' */
int sleep = atoi(opt_sleep);
if (sleep < 1) {
sleep = 1;
global_options global_opts;
const char gpsbabel_version[] = VERSION;
-time_t gpsbabel_now; /* gpsbabel startup-time; initialized in main.c with time() */
-time_t gpsbabel_time; /* gpsbabel startup-time; initialized in main.c with current_time(), ! ZERO within testo ! */
+time_t gpsbabel_time; /* gpsbabel startup-time; initialized in main.c with current_time(), ! fixed within testo ! */
posn_status tracking_status;
// Don't write this line when running test suite. Actually, we should
// probably not write this line at all...
- if (ugetenv("GPSBABEL_FREEZE_TIME").isNull()) {
+ if (!gpsbabel_testmode()) {
gbfprintf(file_out, " <meta name=\"Generator\" content=\"GPSBabel %s\">\n", gpsbabel_version);
}
gbfprintf(file_out, " <title>GPSBabel HTML Output</title>\n");
writer->writeTextElement(QStringLiteral("name"), QStringLiteral("GPS device"));
}
- if (current_time().isValid()) {
+ if (!gpsbabel_testmode()) {
writer->writeTextElement(QStringLiteral("snippet"), QStringLiteral("Created ") +
current_time().toString());
}
global_opts.charset_name.clear();
global_opts.inifile = nullptr;
- gpsbabel_now = time(nullptr); /* gpsbabel startup-time */
- gpsbabel_time = current_time().toTime_t(); /* same like gpsbabel_now, but frozen at zero during testo */
+ gpsbabel_time = current_time().toTime_t(); /* frozen in testmode */
- if (gpsbabel_time != 0) { /* within testo ? */
+ if (!gpsbabel_testmode()) { /* within testo ? */
global_opts.inifile = inifile_init(QString(), MYNAME);
}
if (strlen(created_by) !=0) {
gbfprintf(fout, " <tag k='created_by' v='%s",created_by);
- if (gpsbabel_time != 0)
+ if (!gpsbabel_testmode())
if (strcmp("GPSBabel",created_by)==0) {
gbfprintf(fout, "-%s", gpsbabel_version);
}
if (strlen(created_by) !=0) {
gbfprintf(fout, " <tag k='created_by' v='%s",created_by);
- if (gpsbabel_time != 0)
+ if (!gpsbabel_testmode())
if (strcmp("GPSBabel",created_by)==0) {
gbfprintf(fout, "-%s", gpsbabel_version);
}
{
gbfprintf(fout, "<?xml version='1.0' encoding='UTF-8'?>\n");
gbfprintf(fout, "<osm version='0.6' generator='GPSBabel");
- if (gpsbabel_time != 0) {
+ if (!gpsbabel_testmode()) {
gbfprintf(fout, "-%s", gpsbabel_version);
}
gbfprintf(fout, "'>\n");
#include <QtCore/QDateTime> // for QDateTime
#include <QtCore/QString> // for QString
#include <QtCore/QThread> // for QThread
+#include <QtCore/QVector> // for QVector
#include "defs.h"
#include "garmin_fs.h" // for garmin_fs_t, GMSD_SET, garmin_fs_flags_t, garmin_fs_alloc
}
static void
-random_rd_init(const QString&)
+random_set_generator()
{
generator = new std::mt19937;
if (opt_seed) {
generator->seed(atoi(opt_seed));
} else {
- generator->seed(gpsbabel_now);
+ generator->seed(gpsbabel_time);
}
}
+static void
+random_rd_init(const QString&)
+{
+ random_set_generator();
+}
+
static void
random_rd_deinit()
{
route_head* head;
Waypoint* prev = nullptr;
- QDateTime time = QDateTime::fromTime_t(gpsbabel_time);
+ QDateTime time = current_time();
int points = (opt_points) ? atoi(opt_points) : rand_int(128) + 1;
if (doing_trks || doing_rtes) {
void
random_rd_posn_init(const QString&)
{
- generator = new std::mt19937;
- if (opt_seed) {
- generator->seed(atoi(opt_seed));
- } else {
- generator->seed(gpsbabel_now);
- }
+ random_set_generator();
realtime = new realtime_data;
if (opt_points) {
realtime->points = atoi(opt_points);
}
- realtime->time = QDateTime::fromTime_t(gpsbabel_time);
+ realtime->time = current_time();
}
void
return result;
}
+bool
+gpsbabel_testmode()
+{
+ static bool testmode = getenv("GPSBABEL_FREEZE_TIME") != nullptr;
+ return testmode;
+}
+
/*
* Historically, when we were C, this was A wrapper for time(2) that
* allowed us to "freeze" time for testing. The UNIX epoch
gpsbabel::DateTime
current_time()
{
- if (getenv("GPSBABEL_FREEZE_TIME")) {
+ if (gpsbabel_testmode()) {
return QDateTime::fromTime_t(0);
}
wpt->SetCreationTime(sscanftime(s, fmp.printfc.constData(), 1));
break;
case XT_LOCAL_TIME:
- if (ugetenv("GPSBABEL_FREEZE_TIME").isNull()) {
+ if (!gpsbabel_testmode()) {
wpt->creation_time += sscanftime(s, fmp.printfc.constData(), 0);
} else {
/* Force constant time zone for test */
// Don't do potentially expensive replacements if token prefix
// isn't present;
if (original.contains("__")) {
- time_t my_time = gpsbabel_time;
-
replacement.replace("__FILE__", xcsv_file.fname);
- replacement.replace("__VERSION__", my_time == 0 ? "" : gpsbabel_version);
+ replacement.replace("__VERSION__", gpsbabel_testmode()? "" : gpsbabel_version);
- QDateTime dt = QDateTime::fromTime_t(my_time);
- dt = dt.toTimeSpec(Qt::UTC);
+ QDateTime dt = current_time().toUTC();
QString dts = dt.toString("ddd MMM dd hh:mm:ss yyyy");
replacement.replace("__DATE_AND_TIME__", dts);